package com.springbootweb.controller;

import com.springbootweb.client.ProductClient;
import com.springbootproduct.entity.Product;
//import com.springbootweb.common.Sender;
import com.springbootweb.common.UuidUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.List;
@Api(description = "商品控制器")
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductClient productClient;

//    @Autowired
//    Sender sender;

    @ApiOperation(value = "查询商品列表", notes="调用商品服务，查询商品列表")
    @ApiImplicitParam(name = "product", value = "商品", paramType = "body", required =false, dataType = "Product")
    @PostMapping("/list")
    public List<Product> listData(@Valid @RequestBody Product product, BindingResult bindingResult, HttpSession session){
        return productClient.listData(product);
    }

    @ApiOperation(value = "新增商品", notes="调用商品服务，新增商品信息")
    @ApiImplicitParam(name = "product", value = "商品", paramType = "body", required = true, dataType = "Product")
    @PostMapping("/save")
    public int save(@Valid @RequestBody Product product, BindingResult bindingResult, HttpSession session){
        product.setId(UuidUtil.getint());
        return productClient.save(product);
    }


}
